home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / mui38dev-storm / examples / wbman.c < prev   
C/C++ Source or Header  |  1999-09-13  |  36KB  |  1,595 lines

  1.  
  2.  
  3.   /**********************************************\
  4.   *                                              *
  5.   *  WbMan                                       *
  6.   *                                              *
  7.   *  Version: 0.42 (27.8.93)                     *
  8.   *                                              *
  9.   *  Copyright 1993 by kMel, Klaus Melchior      *
  10.   *  kmel@eifel.adsp.sub.org, 2:242/7.2@Fidonet  *
  11.   *                                              *
  12.   *  Manages the tools in the WBStartup-         *
  13.   *  Folder, the ToolTypes could be changed.     *
  14.   *                                              *
  15.   \**********************************************/
  16.  
  17. /* DMAKE */
  18.  
  19. /* TAB=4 */
  20.  
  21.  
  22.  
  23.  
  24. /*** escape sequences ***/
  25.  
  26. #define eR "\033r"
  27. #define eC "\033c"
  28. #define eL "\033l"
  29.  
  30. #define eN "\033n"
  31. #define eB "\033b"
  32. #define eI "\033i"
  33.  
  34. #define ePB "\0332"
  35. #define ePW "\0338"
  36.  
  37.  
  38.  
  39.  
  40. /*** includes ***/
  41.  
  42. #include "demo.h"
  43. #define MAXNAMELEN 256
  44.  
  45. #include <exec/memory.h>
  46. #include <workbench/workbench.h>
  47. #include <clib/icon_protos.h>
  48.  
  49.  
  50.  
  51.  
  52. /*** ids ***/
  53.  
  54. enum ids {
  55.     ID_DUMMY,
  56.     ID_ABOUT,
  57.     ID_RESCAN, ID_SELECT_ALL, ID_SELECT_NONE, ID_SELECT_PATTERN,
  58.     ID_EDIT, ID_LV_ACTIVE,
  59.     ID_ACTIVATE, ID_TOGGLE, ID_DEACTIVATE, ID_RESTORE,
  60.     ID_PERFORM, ID_QUIT,
  61.  
  62.     ID_STRING_OK, ID_STRING_CANCEL,
  63.  
  64.     ID_EDIT_LV_ACTIVE,
  65.     ID_EDIT_NEW, ID_EDIT_COPY, ID_EDIT_REMOVE,
  66.     ID_EDIT_ACTIVATE, ID_EDIT_DEACTIVATE,
  67.     ID_EDIT_ST_READY,
  68.     ID_EDIT_SAVE, ID_EDIT_CANCEL,
  69. };
  70.  
  71. enum mode_change {
  72.     MODE_ACTIVATE, MODE_DEACTIVATE,
  73.     MODE_TOGGLE, MODE_RESTORE,
  74. };
  75.  
  76.  
  77.  
  78.  
  79. /*** variables ***/
  80.  
  81. static APTR app;
  82. static APTR wi_main;
  83. static APTR lv_tools;
  84. static APTR bt_activate, bt_toggle, bt_deactivate;
  85. static APTR bt_edit;
  86. static APTR tx_info;
  87. static APTR bt_perform, bt_quit;
  88.  
  89. static APTR wi_string_request;
  90. static APTR st_string;
  91. static APTR bt_string_ok, bt_string_cancel;
  92.  
  93. static APTR wi_edit;
  94. static APTR tx_edit;
  95. static APTR lv_edit;
  96. static APTR bt_edit_new, bt_edit_copy, bt_edit_remove;
  97. static APTR bt_edit_activate, bt_edit_deactivate;
  98. static APTR st_edit_string, st_edit_default;
  99. static APTR bt_edit_save, bt_edit_cancel;
  100.  
  101.  
  102. static struct DiskObject *disk_object;
  103. static BOOL temp_dobj_flag;
  104.  
  105. static BOOL edit_window_open = FALSE;
  106. static BOOL string_request_open = FALSE;
  107.  
  108.  
  109.  
  110.  
  111. /*** funcs ***/
  112.  
  113. /*FR* As SAS/C has a lot of custom functions some have to
  114.       replicated so that the app will work with different
  115.       compilers such as StormC */
  116.  
  117. #ifdef __STORM__
  118.  
  119. char *strdup( char *str )
  120. {
  121.     char *outstr;
  122.     int stlen;
  123.  
  124.     if( str )
  125.     {
  126.         if( stlen=strlen( str ) )
  127.         {
  128.             if( outstr=malloc( stlen+1 ) )
  129.             {
  130.                 strcpy( outstr, str );
  131.                 return( outstr );
  132.             }
  133.         }
  134.     }
  135.     return( NULL );
  136. }
  137.  
  138. #endif
  139.  
  140.  
  141. /*** clear tools_listview ***/
  142.  
  143. BOOL clear_tools_list(void)
  144. {
  145.     DoMethod(lv_tools, MUIM_List_Clear);
  146.  
  147.     return(TRUE);
  148. }
  149.  
  150.  
  151.  
  152.  
  153. /*** insert tools in tools_listview ***/
  154.  
  155. BOOL insert_tools_list(void)
  156. {
  157.     BOOL ok = FALSE;
  158.     struct FileInfoBlock *fib;
  159.  
  160.     /*** alloc mem for fileinfoblock ***/
  161.     if (fib = AllocDosObject(DOS_FIB, NULL))
  162.     {
  163.         BPTR lock;
  164.  
  165.         /*** lock on the wbstartup-directory ***/
  166.         if (lock = Lock("SYS:WBStartup/", ACCESS_READ))
  167.         {
  168.             /*** first examine ***/
  169.             Examine(lock, fib);
  170.  
  171.             /*** scan, until last entry ***/
  172.             while (ExNext(lock, fib) && (IoErr()!=ERROR_NO_MORE_ENTRIES))
  173.             {
  174.                 /*** mui refresh ***/
  175.                 DoMethod(app, MUIM_Application_InputBuffered);
  176.  
  177.                 /*** insert fib-entry ***/
  178.                 DoMethod(lv_tools, MUIM_List_Insert, &fib, 1, MUIV_List_Insert_Sorted);
  179.             }
  180.  
  181.             UnLock(lock);
  182.             ok = TRUE;
  183.         }
  184.  
  185.         FreeDosObject(DOS_FIB, fib);
  186.     }
  187.  
  188.     return(ok);
  189. }
  190.  
  191.  
  192.  
  193.  
  194. /*** rescan filenames of tools in the wbstartup-path ***/
  195.  
  196. void rescan_tools_list(void)
  197. {
  198.     if (!(
  199.         clear_tools_list() &&
  200.         insert_tools_list()
  201.         ))
  202.     {
  203.         fail(app,"Lock on 'SYS:WBStartup/' failed !");
  204.     }
  205. }
  206.  
  207.  
  208.  
  209.  
  210. /*** check tool, if it exists in wbstartup-path ***/
  211.  
  212. BOOL check_tool_name(char *n)
  213. {
  214.     char *fn;
  215.     BPTR fh = NULL;
  216.  
  217.     /*** alloc mem for complete filename ***/
  218.     if (fn = AllocMem(MAXNAMELEN, MEMF_ANY))
  219.     {
  220.         sprintf(fn, "SYS:WBStartup/%s", n);
  221.  
  222.         if (fh = Open(fn, MODE_OLDFILE))
  223.             Close(fh);
  224.  
  225.         FreeMem(fn, MAXNAMELEN);
  226.     }
  227.  
  228.     return((BOOL) fh);
  229. }
  230.  
  231.  
  232.  
  233.  
  234. /*** count active & inactive tools ***/
  235.  
  236. void count_tools_list(void)
  237. {
  238.     ULONG i;
  239.     UWORD nr_active = 0, nr_inactive = 0, nr_changed = 0;
  240.     char *line;
  241.  
  242.     /*** count ***/
  243.     for (i=0; ; i++)
  244.     {
  245.         DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  246.  
  247.         /*** last line ? ***/
  248.         if (!line)
  249.             break;
  250.  
  251.         /*** count tools ***/
  252.         if (*(line+2) == '8')
  253.             nr_active++;
  254.         else
  255.             nr_inactive++;
  256.  
  257.         if (*(line+4) == 'b')
  258.             nr_changed++;
  259.     }
  260.  
  261.     {
  262.         char *s_inactive = "s";
  263.  
  264.         /*** check if 'tool' or 'tools' ***/
  265.         if (nr_inactive == 1)
  266.             s_inactive = "";
  267.  
  268.         /*** generate info text ***/
  269.         DoMethod(tx_info, MUIM_SetAsString, MUIA_Text_Contents,
  270.             eC ePB "%ld tool%s inactive · " ePW "%ld active · " eB ePB "%ld changed",
  271.             nr_inactive, s_inactive, nr_active, nr_changed);
  272.     }
  273. }
  274.  
  275.  
  276.  
  277.  
  278.  
  279. /*** disable gadgets & menus, show changes ***/
  280.  
  281. void check_entries(void)
  282. {
  283.     ULONG i, sel, c_pos;
  284.     UWORD nr_active = 0, nr_inactive = 0, nr_selected = 0;
  285.     char *line;
  286.  
  287.     BOOL disable_activate = TRUE, disable_toggle = TRUE;
  288.     BOOL disable_deactivate = TRUE, disable_restore = TRUE;
  289.     BOOL disable_perform = TRUE, disable_edit = TRUE;
  290.  
  291.     BOOL refresh_display = FALSE;
  292.  
  293.  
  294.     /*** cursor position ***/
  295.     get(lv_tools, MUIA_List_Active, &c_pos);
  296.  
  297.     /*** count ***/
  298.     for (i=0;; i++)
  299.     {
  300.         DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  301.  
  302.         /*** last line ? ***/
  303.         if (!line)
  304.             break;
  305.  
  306.         /*** count selected or at cursor-position ***/
  307.         DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_Ask, &sel);
  308.         if (sel || i==c_pos)
  309.         {
  310.             /*** count status of selected tools ***/
  311.             if (*(line+2)=='8')
  312.                 nr_active++;
  313.             else
  314.                 nr_inactive++;
  315.  
  316.             nr_selected++;
  317.         }
  318.  
  319.         /*** check difference between stored and new status ***/
  320.         if (*(line+2) != *line)
  321.         {
  322.             /*** make entry bold ***/
  323.             if (*(line+4)!='b')
  324.                 refresh_display = TRUE;
  325.             *(line+4)='b';
  326.  
  327.             disable_perform = FALSE;
  328.         }
  329.         else
  330.         {
  331.             /*** now a normal entry ***/
  332.             if (*(line+4)!='n')
  333.                 refresh_display = TRUE;
  334.             *(line+4)='n';
  335.         }
  336.     }
  337.  
  338.     if (nr_selected > 0)
  339.     {
  340.         disable_toggle = FALSE;
  341.         disable_restore = FALSE;
  342.  
  343.         if (nr_inactive)
  344.             disable_activate = FALSE;
  345.  
  346.         if (nr_active)
  347.             disable_deactivate = FALSE;
  348.     }
  349.  
  350.     if (nr_selected == 1)
  351.         disable_edit = FALSE;
  352.  
  353.  
  354.     /*** set status of gadgets ***/
  355.     set(bt_perform, MUIA_Disabled, disable_perform);
  356.  
  357.     set(bt_activate, MUIA_Disabled, disable_activate);
  358.     set(bt_toggle, MUIA_Disabled, disable_toggle);
  359.     set(bt_deactivate, MUIA_Disabled, disable_deactivate);
  360.     set(bt_edit, MUIA_Disabled, disable_edit);
  361.  
  362.  
  363.     /*** set status of menus ***/
  364.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_PERFORM, !disable_perform);
  365.  
  366.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_ACTIVATE, !disable_activate);
  367.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_DEACTIVATE, !disable_deactivate);
  368.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_TOGGLE, !disable_toggle);
  369.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_RESTORE, !disable_restore);
  370.  
  371.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_EDIT, !disable_edit);
  372.  
  373.     /*** refresh display ***/
  374.     if (refresh_display)
  375.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  376. }
  377.  
  378.  
  379.  
  380.  
  381. /*** change status of tools ***/
  382.  
  383. void change_tools_list_entry(LONG pos, UWORD mode)
  384. {
  385.     char *line, *pen;
  386.  
  387.     /*** get entry ***/
  388.     DoMethod(lv_tools, MUIM_List_GetEntry, pos, &line);
  389.     pen = line+2;
  390.  
  391.     /*** change entry ***/
  392.     switch (mode)
  393.     {
  394.         case MODE_ACTIVATE:
  395.             *pen = '8';
  396.         break;
  397.  
  398.         case MODE_DEACTIVATE:
  399.             *pen = '2';
  400.         break;
  401.  
  402.         case MODE_TOGGLE:
  403.             if (*pen=='2')
  404.                 *pen = '8';
  405.             else
  406.                 *pen = '2';
  407.         break;
  408.  
  409.         case MODE_RESTORE:
  410.             *pen = *line;
  411.         break;
  412.     }
  413. }
  414.  
  415. void change_tools_list_entry_cursor(UWORD mode)
  416. {
  417.     LONG i;
  418.  
  419.     get(lv_tools, MUIA_List_Active, &i);
  420.  
  421.     if (i >= 0)
  422.     {
  423.         change_tools_list_entry(i, mode);
  424.         DoMethod(lv_tools, MUIM_List_Redraw, i);
  425.     }
  426. }
  427.  
  428. void change_tools_list(UWORD mode)
  429. {
  430.     ULONG end, i, nr=0;
  431.     ULONG sel;
  432.  
  433.     /*** get number of all entries ***/
  434.     get(lv_tools, MUIA_List_Entries, &end);
  435.  
  436.     set(lv_tools, MUIA_List_Quiet, TRUE);
  437.     for (i=0; i<end ; i++)
  438.     {
  439.         /*** entry selected ? ***/
  440.         DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_Ask, &sel);
  441.         if (sel)
  442.         {
  443.             change_tools_list_entry(i, mode);
  444.             nr++;
  445.         }
  446.     }
  447.     set(lv_tools, MUIA_List_Quiet, FALSE);
  448.  
  449.     /*** refresh display, if almost one entry is selected ***/
  450.     if (nr>0)
  451.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  452.  
  453.     /*** change entry on cursor-position ***/
  454.     else
  455.         change_tools_list_entry_cursor(mode);
  456. }
  457.  
  458.  
  459.  
  460.  
  461. /*** select every entry of tools_list ***/
  462.  
  463. void select_tools_list(ULONG mode)
  464. {
  465.     ULONG end, i;
  466.     ULONG sel;
  467.  
  468.     /*** get number of all entries ***/
  469.     get(lv_tools, MUIA_List_Entries, &end);
  470.  
  471.     for (i=0; i<end ; i++)
  472.         DoMethod(lv_tools, MUIM_List_Select, i, mode, &sel);
  473.  
  474.     /*** refresh display ***/
  475.     DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  476. }
  477.  
  478.  
  479.  
  480.  
  481. /*** select tools of tools_list matching pattern ***/
  482.  
  483. void select_pattern_tools_list(char *pattern)
  484. {
  485.     ULONG end, i;
  486.     ULONG sel;
  487.     char *tool_name, *pattern_token;
  488.  
  489.     /*** alloc mem for pattern_name ***/
  490.     if (pattern_token = AllocMem(MAXNAMELEN, MEMF_ANY))
  491.     {
  492.         /*** tokenize pattern ***/
  493.         ParsePatternNoCase(pattern, pattern_token, MAXNAMELEN);
  494.  
  495.         /*** get number of all entries ***/
  496.         get(lv_tools, MUIA_List_Entries, &end);
  497.  
  498.         for (i=0; i<end ; i++)
  499.         {
  500.             DoMethod(lv_tools, MUIM_List_GetEntry, i, &tool_name);
  501.  
  502.             /*** check tool_name, if it fits on pattern ***/
  503.             if (MatchPatternNoCase(pattern_token, tool_name+5))
  504.                 DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_On, &sel);
  505.         }
  506.  
  507.         /*** refresh display ***/
  508.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  509.  
  510.         FreeMem(pattern_token, MAXNAMELEN);
  511.     }
  512. }
  513.  
  514.  
  515.  
  516.  
  517. /*** rename the tools in the wbstartup-directory ***/
  518.  
  519. void rename_tools_list(void)
  520. {
  521.     char *file_name, *new_file_name;
  522.  
  523.     /*** alloc mem for filenames ***/
  524.     if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  525.     {
  526.         if (new_file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  527.         {
  528.             char *line;
  529.             ULONG i;
  530.  
  531.             for (i=0; ; i++)
  532.             {
  533.                 DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  534.  
  535.                 if (!line)
  536.                     break;
  537.  
  538.                 /*** check if old and new status different ***/
  539.                 if (*(line+4) == 'b')
  540.                 {
  541.  
  542.                     /*** turn status to active ***/
  543.                     if (*(line+2) == '8')
  544.                     {
  545.                         sprintf(file_name, "SYS:WBStartup/%s.noinfo", line+5);
  546.                         sprintf(new_file_name, "SYS:WBStartup/%s.info", line+5);
  547.                     }
  548.  
  549.                     /*** turn status to inactive ***/
  550.                     else
  551.                     {
  552.                         sprintf(file_name, "SYS:WBStartup/%s.info", line+5);
  553.                         sprintf(new_file_name, "SYS:WBStartup/%s.noinfo", line+5);
  554.                     }
  555.  
  556.                     if (rename(file_name, new_file_name))
  557.                         printf("Can't rename: '%s' -> '%s'\n", file_name, new_file_name);
  558.                 }
  559.             }
  560.             FreeMem(new_file_name, MAXNAMELEN);
  561.  
  562.         }
  563.         FreeMem(file_name, MAXNAMELEN);
  564.  
  565.     }
  566. }
  567.  
  568.  
  569.  
  570.  
  571. /*** string requester ***/
  572.  
  573. /*** open requester ***/
  574.  
  575. BOOL open_string_request(char *title_text, ULONG string_len)
  576. {
  577.     wi_string_request = WindowObject,
  578.         MUIA_Window_ID, MAKE_ID('S','R','E','Q'),
  579.         MUIA_Window_Title, "WbMan",
  580.         MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  581.         WindowContents, VGroup,
  582.             Child, HGroup,
  583.                 GroupFrameT(title_text),
  584.                 Child, st_string = StringObject,
  585.                     StringFrame,
  586.                     MUIA_String_MaxLen, string_len,
  587.                     End,
  588.                 End,
  589.             Child, VSpace(2),
  590.             Child, HGroup,
  591.                 MUIA_Group_SameSize, TRUE,
  592.                 Child, bt_string_ok = SimpleButton("_OK"),
  593.                 Child, HSpace(0),
  594.                 Child, bt_string_cancel = SimpleButton("_Cancel"),
  595.                 End,
  596.             End,
  597.         End;
  598.  
  599.  
  600.     /*** string requester failed ? ***/
  601.     if (!wi_string_request)
  602.         fail(app, "Creating string-requester failed !");
  603.  
  604.  
  605.  
  606.     /*** connections & cycle ***/
  607.  
  608.     DoMethod(wi_string_request,    MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_CANCEL    );
  609.  
  610.     DoMethod(bt_string_ok,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_OK        );
  611.     DoMethod(bt_string_cancel,    MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_CANCEL    );
  612.  
  613.     /*** activate ok-button if string is ready ***/
  614.     DoMethod(st_string,
  615.         MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  616.         wi_string_request, 3,
  617.         MUIM_Set, MUIA_Window_ActiveObject, bt_string_ok);
  618.  
  619.     DoMethod(wi_string_request, MUIM_Window_SetCycleChain,
  620.         st_string,
  621.         bt_string_ok, bt_string_cancel,
  622.         NULL);
  623.  
  624.  
  625.     /*** add & open window ***/
  626.  
  627.     DoMethod(app, OM_ADDMEMBER, wi_string_request);
  628.     set(wi_string_request, MUIA_Window_Open            , TRUE);
  629.     set(wi_string_request, MUIA_Window_ActiveObject    , st_string);
  630.  
  631.     return(TRUE);
  632. }
  633.  
  634.  
  635. /*** close requester ***/
  636.  
  637. void close_string_request(void)
  638. {
  639.     /*** close & remove window ***/
  640.     set(wi_string_request, MUIA_Window_Open, FALSE);
  641.     DoMethod(app, OM_REMMEMBER, wi_string_request);
  642.     MUI_DisposeObject(wi_string_request);
  643.  
  644.     /*** wake up main-window ***/
  645.     set(wi_main, MUIA_Window_Sleep, FALSE);
  646. }
  647.  
  648.  
  649.  
  650.  
  651. /*** edit tooltypes ***/
  652.  
  653. /*** open edit-window ***/
  654.  
  655. BOOL open_edit_window(struct DiskObject *dobj, char *name)
  656. {
  657.     wi_edit = WindowObject,
  658.         MUIA_Window_ID, MAKE_ID('E','D','I','T'),
  659.         MUIA_Window_Title, "WbMan",
  660.         MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  661.         WindowContents, VGroup,
  662.             Child, HGroup,
  663.                 TextFrame,
  664.                 InnerSpacing(4,3),
  665.                 Child, ImageObject,
  666.                     MUIA_Image_OldImage, dobj->do_Gadget.GadgetRender,
  667.                     End,
  668.                 Child, VGroup,
  669.                     Child, VSpace(0),
  670.                     Child, tx_edit = TextObject,
  671.                         MUIA_Text_PreParse, eC,
  672.                         MUIA_Text_Contents, name,
  673.                         MUIA_Text_SetMin, TRUE,
  674.                         End,
  675.                     Child, VSpace(0),
  676.                     End,
  677.                 Child, ImageObject,
  678.                     MUIA_Image_OldImage, dobj->do_Gadget.GadgetRender,
  679.                     End,
  680.                 End,
  681.             Child, VGroup,
  682.                 GroupFrameT("ToolTypes"),
  683.                 Child, VGroup,
  684.                     GroupSpacing(0),
  685.                     Child, lv_edit = ListviewObject,
  686.                         MUIA_Listview_Input, TRUE,
  687.                         MUIA_Listview_List, ListObject,
  688.                             InputListFrame,
  689.                             MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  690.                             MUIA_List_DestructHook, MUIV_List_DestructHook_String,
  691.                             End,
  692.                         End,
  693.                     Child, HGroup,
  694.                         GroupSpacing(0),
  695.                         Child, bt_edit_new = SimpleButton("_New"),
  696.                         Child, bt_edit_copy = SimpleButton("Cop_y"),
  697.                         Child, bt_edit_remove = SimpleButton("_Remove"),
  698.                         End,
  699.                     Child, HGroup,
  700.                         GroupSpacing(0),
  701.                         Child, bt_edit_activate = SimpleButton("_Activate"),
  702.                         Child, bt_edit_deactivate = SimpleButton("_Deactivate"),
  703.                         End,
  704.                     Child, st_edit_string = StringObject,
  705.                         StringFrame,
  706.                         End,
  707.                     End,
  708.                 End,
  709.             Child, HGroup,
  710.                 Child, Label2("Default Tool:"),
  711.                 Child, st_edit_default = String(NULL, MAXNAMELEN),
  712.                 End,
  713.             Child, VSpace(2),
  714.             Child, HGroup,
  715.                 MUIA_Group_SameSize, TRUE,
  716.                 Child, bt_edit_save = SimpleButton("_Save"),
  717.                 Child, HSpace(0),
  718.                 Child, bt_edit_cancel = SimpleButton("_Cancel"),
  719.                 End,
  720.             End,
  721.         End;
  722.  
  723.  
  724.     /*** window failed ? ***/
  725.     if (!wi_edit)
  726.         fail(app, "Creating edit-window failed !");
  727.  
  728.  
  729.     /*** connections & cycle ***/
  730.  
  731.     DoMethod(wi_edit,                MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_CANCEL        );
  732.  
  733.     DoMethod(bt_edit_new,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_NEW            );
  734.     DoMethod(bt_edit_copy,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_COPY        );
  735.     DoMethod(bt_edit_remove,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_REMOVE        );
  736.  
  737.     DoMethod(bt_edit_activate,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_ACTIVATE    );
  738.     DoMethod(bt_edit_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_DEACTIVATE    );
  739.  
  740.     DoMethod(bt_edit_save,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_SAVE        );
  741.     DoMethod(bt_edit_cancel,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_CANCEL        );
  742.  
  743.     DoMethod(lv_edit,                MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_LV_ACTIVE    );
  744.  
  745.     set(lv_edit, MUIA_List_Active, MUIV_List_Active_Top);
  746.     DoMethod(lv_edit,
  747.         MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  748.         app, 2,
  749.         MUIM_Application_ReturnID, ID_EDIT_LV_ACTIVE);
  750.  
  751.     set(st_edit_string, MUIA_String_AttachedList, lv_edit);
  752.     DoMethod(st_edit_string,
  753.         MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  754.         app, 2,
  755.         MUIM_Application_ReturnID,  ID_EDIT_ST_READY);
  756.  
  757.     DoMethod(wi_edit, MUIM_Window_SetCycleChain,
  758.         st_edit_string,
  759.         bt_edit_new, bt_edit_copy, bt_edit_remove,
  760.         st_edit_default,
  761.         bt_edit_save, bt_edit_cancel,
  762.         NULL);
  763.  
  764.  
  765.     /*** add & open window ***/
  766.     DoMethod(app, OM_ADDMEMBER, wi_edit);
  767.     set(wi_edit, MUIA_Window_Open, TRUE);
  768.     set(wi_edit, MUIA_Window_ActiveObject, st_edit_string);
  769.  
  770.     return(TRUE);
  771. }
  772.  
  773.  
  774. /*** close edit-window ***/
  775.  
  776. void close_edit_window(void)
  777. {
  778.     /*** close & remove window ***/
  779.     set(wi_edit, MUIA_Window_Open, FALSE);
  780.     DoMethod(app, OM_REMMEMBER, wi_edit);
  781.     MUI_DisposeObject(wi_edit);
  782.  
  783.     if (disk_object)
  784.         FreeDiskObject(disk_object);
  785.  
  786.     /*** wake up main-window ***/
  787.     set(wi_main, MUIA_Window_Sleep, FALSE);
  788. }
  789.  
  790.  
  791. /*** disable gadgets ***/
  792.  
  793. void check_edit_entries(void)
  794. {
  795.     LONG pos;
  796.     char *line;
  797.  
  798.     BOOL disable_cursor = TRUE;
  799.     BOOL disable_activate = TRUE, disable_deactivate = TRUE;
  800.  
  801.  
  802.     /*** cursor position ***/
  803.     get(lv_edit, MUIA_List_Active, &pos);
  804.  
  805.     if (pos >= 0)
  806.     {
  807.         disable_cursor = FALSE;
  808.  
  809.         /*** get active line ***/
  810.         DoMethod(lv_edit, MUIM_List_GetEntry, pos, &line);
  811.  
  812.         /*** check if there are brakets -> inactive ***/
  813.         if (*line == '(' && *(line + strlen(line) - 1) == ')')
  814.             disable_activate = FALSE;
  815.         else
  816.             disable_deactivate = FALSE;
  817.     }
  818.  
  819.     set(bt_edit_copy, MUIA_Disabled, disable_cursor);
  820.     set(bt_edit_remove, MUIA_Disabled, disable_cursor);
  821.     set(st_edit_string, MUIA_Disabled, disable_cursor);
  822.  
  823.     set(bt_edit_activate, MUIA_Disabled, disable_activate);
  824.     set(bt_edit_deactivate, MUIA_Disabled, disable_deactivate);
  825.  
  826.     /*** clear string if disabled ***/
  827.     if (disable_cursor)
  828.         set(st_edit_string, MUIA_String_Contents, "");
  829.  
  830. }
  831.  
  832.  
  833. /*** edit the active tool ***/
  834.  
  835. void edit_tooltypes_diskobject(struct DiskObject *dobj, char *fn)
  836. {
  837.     char **tt;
  838.  
  839.     /*** open window ***/
  840.     if (open_edit_window(dobj, fn))
  841.     {
  842.         tt = dobj->do_ToolTypes;
  843.  
  844.         /*** copy tooltype-array into listview ***/
  845.         while (tt && *tt)
  846.             DoMethod(lv_edit, MUIM_List_Insert, tt++, 1, MUIV_List_Insert_Bottom);
  847.  
  848.         /*** fill in strings ***/
  849.         set(st_edit_default, MUIA_String_Contents, dobj->do_DefaultTool);
  850.         set(lv_edit, MUIA_List_Active, MUIV_List_Active_Top);
  851.     }
  852. }
  853.  
  854. void edit_tooltypes_entry(void)
  855. {
  856.     char *file_name;
  857.  
  858.     if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  859.     {
  860.         char *line;
  861.  
  862.         /*** get entry ***/
  863.         DoMethod(lv_tools, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  864.  
  865.         sprintf(file_name, "SYS:WBStartup/%s", line+5);
  866.  
  867.         if (disk_object = GetDiskObject(file_name))
  868.         {
  869.             temp_dobj_flag = FALSE;
  870.             edit_tooltypes_diskobject(disk_object, line+5);
  871.         }
  872.         else
  873.         {
  874.             /*** is tool inactive ? create temporary .info-file ***/
  875.             temp_dobj_flag = TRUE;
  876.             sprintf(file_name, "copy SYS:WBStartup/%s.noinfo T:WbMan_Temp.info", line+5);
  877.             if (Execute(file_name, NULL, NULL) &&
  878.                 (disk_object = GetDiskObjectNew("T:WbMan_Temp"))
  879.                 )
  880.                 edit_tooltypes_diskobject(disk_object, line+5);
  881.             else
  882.             {
  883.             }
  884.         }
  885.  
  886.         check_edit_entries();
  887.  
  888.         FreeMem(file_name, MAXNAMELEN);
  889.     }
  890. }
  891.  
  892. void save_tooltypes(void)
  893. {
  894.     if (disk_object)
  895.     {
  896.         char *file_name;
  897.  
  898.         if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  899.         {
  900.             char *old_def_tool;
  901.             char **old_tooltypes;
  902.             char *line;
  903.             ULONG nr;
  904.             char **new_tooltypes;
  905.  
  906.             /*** store actual data ***/
  907.             old_def_tool = disk_object->do_DefaultTool;
  908.             old_tooltypes = disk_object->do_ToolTypes;
  909.  
  910.             /*** new data ***/
  911.             get(st_edit_default, MUIA_String_Contents, &line);
  912.             disk_object->do_DefaultTool = line;
  913.  
  914.             /*** generate array of tooltypes ***/
  915.             get(lv_edit, MUIA_List_Entries, &nr);
  916.             if (new_tooltypes = AllocMem((nr+1) << 2, MEMF_ANY))
  917.             {
  918.                 char **l;
  919.                 ULONG i;
  920.  
  921.                 l = new_tooltypes;
  922.                 for (i=0; ; i++)
  923.                 {
  924.                     DoMethod(lv_edit, MUIM_List_GetEntry, i, &line);
  925.  
  926.                     /*** last line ? ***/
  927.                     if (!line)
  928.                         break;
  929.  
  930.                     *l++ = line;
  931.                 }
  932.                 /*** terminate array ***/
  933.                 *l = NULL;
  934.  
  935.                 /*** new_data ***/
  936.                 disk_object->do_ToolTypes = new_tooltypes;
  937.  
  938.                 /*** get entry ***/
  939.                 DoMethod(lv_tools, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  940.  
  941.                 if (temp_dobj_flag)
  942.                 {
  943.                     PutDiskObject("T:WbMan_Temp", disk_object);
  944.  
  945.                     sprintf(file_name, "copy T:WbMan_Temp.info SYS:WBStartup/%s.noinfo", line+5);
  946.                     Execute(file_name, NULL, NULL);
  947.                 }
  948.                 else
  949.                 {
  950.                     /*** get disk object ***/
  951.                     sprintf(file_name, "SYS:WBStartup/%s", line+5);
  952.  
  953.                     PutDiskObject(file_name, disk_object);
  954.                 }
  955.  
  956.                 FreeMem(new_tooltypes, (nr+1) << 2);
  957.             }
  958.  
  959.             /*** restore data ***/
  960.             disk_object->do_DefaultTool = old_def_tool;
  961.             disk_object->do_ToolTypes = old_tooltypes;
  962.  
  963.             FreeMem(file_name, MAXNAMELEN);
  964.         }
  965.     }
  966. }
  967.  
  968.  
  969.  
  970.  
  971. /*** image-stuff ***/
  972.  
  973. static UWORD wbman_sleep_img1_data[] = {
  974.     0x0003,0xc000,0x0000,0x0000,0x0004,0x4000,0x0000,0x0000,
  975.     0x0008,0x4000,0x0000,0x0000,0x0018,0x4de0,0x0000,0x0000,
  976.     0x0020,0x3210,0x0000,0x0000,0x0020,0x0008,0x0000,0x0000,
  977.     0x0020,0x0008,0x0000,0x0000,0x0020,0xf008,0x0000,0x0000,
  978.     0x0020,0x2788,0x0000,0x0000,0x0010,0x4108,0x0000,0x0000,
  979.     0x0010,0xf208,0x0000,0x0000,0x0008,0x0790,0x0000,0x0000,
  980.     0x0008,0x0020,0x0000,0x0000,0x003c,0x00c0,0x0000,0x0400,
  981.     0x0046,0x3f00,0x0000,0x0c00,0x0083,0xe000,0x0000,0x0c00,
  982.     0x0100,0x8004,0x0000,0x2c00,0x0101,0x001c,0x0000,0x2c00,
  983.     0x0386,0x007e,0x0000,0x2c00,0x04c8,0x01fe,0x0001,0x2c00,
  984.     0x08b0,0x07f8,0x0001,0x2c00,0x0500,0x1fe0,0x0001,0x2c00,
  985.     0x0200,0x7f80,0x0009,0x2c00,0x0001,0xfe00,0x0009,0x2c00,
  986.     0x0007,0xf8f8,0x2009,0x2c00,0x001f,0xe1cc,0x7009,0x2c00,
  987.     0x007f,0x8038,0x7009,0xcc00,0x01fe,0x0070,0x2009,0x0c00,
  988.     0x01f8,0x0000,0x0009,0x0c00,0x00e0,0x0070,0x700e,0x0c00,
  989.     0x0080,0x0000,0x0008,0x0c00,0x0000,0x0000,0x0008,0x0c00,
  990.     0x0000,0x3fff,0xfff0,0x0c00,0x0000,0x0000,0x0000,0x0c00,
  991.     0x7fff,0xffff,0xffff,0xfc00,0x0003,0xc000,0x0000,0x0000,
  992.     0x0007,0xc000,0x0000,0x0000,0x000f,0xc000,0x0000,0x0000,
  993.     0x001f,0xcde0,0x0000,0x0000,0x003f,0xfff0,0x0000,0x0000,
  994.     0x003f,0xfff8,0x0000,0x0000,0x003f,0xfff8,0x0000,0x0000,
  995.     0x003f,0x0ff8,0x0000,0x0000,0x003f,0xd878,0x0000,0x0000,
  996.     0x001f,0xbef8,0x0000,0x0000,0x001f,0x0df8,0x0000,0x0000,
  997.     0x000f,0xf870,0x0000,0x0000,0x000f,0xffe0,0x0000,0x0000,
  998.     0xffff,0xffff,0xffff,0xf800,0xd57f,0xff54,0x1555,0x5000,
  999.     0xd5ff,0xf5f8,0xcfff,0xd000,0xd5ff,0xd7e7,0xefff,0x9000,
  1000.     0xd5ff,0x5713,0xcaa9,0x1000,0xd7ff,0x5e41,0x1ffe,0x1000,
  1001.     0xd7fd,0x5902,0x7ffc,0x1000,0xdff5,0x4409,0x5548,0x1000,
  1002.     0xd755,0x1027,0xfff0,0x1000,0xd754,0x409f,0xffe0,0x1000,
  1003.     0xd551,0x022a,0xaa40,0x1000,0xd544,0x0802,0x8a80,0x1000,
  1004.     0xd510,0x2222,0x8a80,0x9000,0xd440,0x8a82,0x8a80,0x3000,
  1005.     0xd102,0x6a8a,0x8a80,0x5000,0xc209,0xeaaa,0xaa84,0x5000,
  1006.     0xcf25,0xea8a,0x8a81,0x5000,0xdf95,0xf2aa,0xaa45,0x5000,
  1007.     0xcc55,0xe000,0x0025,0x5000,0xc155,0xc000,0x000d,0x5000,
  1008.     0xd555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000,
  1009.  
  1010. };
  1011.  
  1012. static struct Image wbman_sleep_img1 = {
  1013.     0x0000,0x0000,0x0036,0x0023,0x0002,
  1014.     &wbman_sleep_img1_data[0],
  1015.     0x03,0x00,0x00000000,
  1016. };
  1017.  
  1018. static struct DiskObject wbman_sleep_dobj = {
  1019.     0xe310,0x0001,
  1020.     0x00000000,
  1021.     0x00a9,0x00fa,0x0036,0x0024,0x0005,0x0001,0x95a5,
  1022.     (APTR)&wbman_sleep_img1,NULL,
  1023.     0x00000000,0x00000000,0x00000000,
  1024.     0x0064,
  1025.     0x00000000,
  1026.     0x0003,
  1027.     0x00000000,0x00000000,0x000000a5,0x000000e5,
  1028.     0x00000000,0x00000000,0x00001000
  1029. };
  1030.  
  1031.  
  1032.  
  1033.  
  1034. /*** mui-stuff ***/
  1035.  
  1036. /*** list hooks ***/
  1037.  
  1038. #ifdef __STORM__
  1039. char *tools_list_confunc(
  1040. #else
  1041. SAVEDS ASM char *tools_list_confunc(
  1042. #endif
  1043.     REG(a0) struct Hook *hook,
  1044.     REG(a2) APTR mem_pool,
  1045.     REG(a1) struct FileInfoBlock *fib)
  1046. {
  1047.     char active_pattern[14];
  1048.     char inactive_pattern[20];
  1049.  
  1050.     /*** tokenize pattern ***/
  1051.     ParsePatternNoCase("#?.info", active_pattern, 14);
  1052.     ParsePatternNoCase("#?.noinfo", inactive_pattern, 20);
  1053.  
  1054.     /*** check, only files ***/
  1055.     if (fib->fib_DirEntryType < 0)
  1056.     {
  1057.         char *file_name, *entry;
  1058.  
  1059.         if (entry = AllocMem(MAXNAMELEN, MEMF_ANY))
  1060.         {
  1061.             file_name = &fib->fib_FileName[0];
  1062.  
  1063.             /*** check if active ***/
  1064.             if (MatchPatternNoCase(active_pattern, file_name))
  1065.             {
  1066.                 /*** cut the ".info" at end ***/
  1067.                 *(file_name + strlen(file_name) - 5) = 0;
  1068.  
  1069.                 /*** valid filename ? ***/
  1070.                 if (check_tool_name(file_name))
  1071.                 {
  1072.                     sprintf(entry, "8" ePW eN "%s", file_name);
  1073.                     return(entry);
  1074.                 }
  1075.             }
  1076.  
  1077.             /*** or inactive ***/
  1078.             else if (MatchPatternNoCase(inactive_pattern, file_name))
  1079.             {
  1080.                 /*** cut the ".noinfo" at end ***/
  1081.                 *(file_name + strlen(file_name) - 7) = 0;
  1082.  
  1083.                 /*** valid filename ? ***/
  1084.                 if (check_tool_name(file_name))
  1085.                 {
  1086.                     sprintf(entry, "2" ePB eN "%s", file_name);
  1087.                     return(entry);
  1088.                 }
  1089.             }
  1090.  
  1091.             FreeMem(entry, MAXNAMELEN);
  1092.         }
  1093.     }
  1094.  
  1095.     /*** insert nothing ***/
  1096.     return(0);
  1097. }
  1098.  
  1099. static struct Hook tools_list_conhook = {
  1100.     {NULL, NULL},
  1101.     (void *)tools_list_confunc,
  1102.     NULL, NULL
  1103. };
  1104.  
  1105.  
  1106. SAVEDS ASM LONG tools_list_desfunc(
  1107.     REG(a0) struct Hook *hook,
  1108.     REG(a2) APTR mem_pool,
  1109.     REG(a1) char *line)
  1110. {
  1111.     FreeMem(line, MAXNAMELEN);
  1112.  
  1113.     return(0);
  1114. }
  1115.  
  1116. static struct Hook tools_list_deshook = {
  1117.     {NULL, NULL},
  1118.     (void *)tools_list_desfunc,
  1119.     NULL, NULL
  1120. };
  1121.  
  1122.  
  1123. SAVEDS ASM LONG tools_list_dspfunc(
  1124.     REG(a0) struct Hook *hook,
  1125.     REG(a2) char **array,
  1126.     REG(a1) char *line)
  1127. {
  1128.     *array = line+1;
  1129.     return(0);
  1130. }
  1131.  
  1132. static struct Hook tools_list_dsphook = {
  1133.     {NULL, NULL},
  1134.     (void *)tools_list_dspfunc,
  1135.     NULL, NULL
  1136. };
  1137.  
  1138.  
  1139. SAVEDS ASM LONG tools_list_cmpfunc(
  1140.     REG(a0) struct Hook *hook,
  1141.     REG(a2) char *line1,
  1142.     REG(a1) char *line2)
  1143. {
  1144.     return(stricmp(line2+5, line1+5));
  1145. }
  1146.  
  1147. static struct Hook tools_list_cmphook = {
  1148.     {NULL, NULL},
  1149.     (void *)tools_list_cmpfunc,
  1150.     NULL, NULL
  1151. };
  1152.  
  1153.  
  1154.  
  1155. /*** arexx hooks ***/
  1156.  
  1157. SAVEDS ASM APTR select_rxfunc(
  1158.     REG(a0) struct Hook *hook,
  1159.     REG(a2) Object *appl,
  1160.     REG(a1) ULONG *arg)
  1161. {
  1162.     char *pattern;
  1163.  
  1164.     /*** pattern valid ? ***/
  1165.     if (pattern = (char *)*arg)
  1166.     {
  1167.         /*** clear list & select matching pattern ***/
  1168.         select_tools_list(MUIV_List_Select_Off);
  1169.         select_pattern_tools_list(pattern);
  1170.     }
  1171.  
  1172.     return(RETURN_OK);
  1173. }
  1174.  
  1175. static const struct Hook select_rxhook = {
  1176.     {NULL, NULL},
  1177.     (void *)select_rxfunc,
  1178.     NULL,NULL
  1179. };
  1180.  
  1181.  
  1182.  
  1183.  
  1184. /*** arexx list ***/
  1185.  
  1186. static struct MUI_Command arexx_list[] =
  1187. {
  1188.     {"rescan",        MC_TEMPLATE_ID,        ID_RESCAN,        NULL},
  1189.  
  1190.     {"select",        "PATTERN/A",        1,                &select_rxhook},
  1191.  
  1192.     {"activate",    MC_TEMPLATE_ID,        ID_ACTIVATE,    NULL},
  1193.     {"deactivate",    MC_TEMPLATE_ID,        ID_DEACTIVATE,    NULL},
  1194.     {"toggle",        MC_TEMPLATE_ID,        ID_TOGGLE,        NULL},
  1195.     {"restore",        MC_TEMPLATE_ID,        ID_RESTORE,        NULL},
  1196.  
  1197.     {NULL,            NULL,                0,                NULL}
  1198. };
  1199.  
  1200.  
  1201.  
  1202. /*** menu ***/
  1203.  
  1204. static const struct NewMenu menu_list[] =
  1205. {
  1206.     { NM_TITLE,    "Project",            0,    0,    0,    0                            },
  1207.  
  1208.     { NM_ITEM,    "About...",            "?",0,    0,    (APTR) ID_ABOUT                },
  1209.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1210.     { NM_ITEM,    "Rescan",            "S",0,    0,    (APTR) ID_RESCAN            },
  1211.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1212.     { NM_ITEM,    "Perform",            "P",0,    0,    (APTR) ID_PERFORM            },
  1213.     { NM_ITEM,    "Quit",                "Q",0,    0,    (APTR) ID_QUIT                },
  1214.  
  1215.  
  1216.     { NM_TITLE,    "Tools",            0,    0,    0,    0                            },
  1217.  
  1218.     { NM_ITEM,    "Select All",        "A",0,    0,    (APTR) ID_SELECT_ALL        },
  1219.     { NM_ITEM,    "Select None",        "N",0,    0,    (APTR) ID_SELECT_NONE        },
  1220.     { NM_ITEM,    "Select Pattern",    "E",0,    0,    (APTR) ID_SELECT_PATTERN    },
  1221.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1222.     { NM_ITEM,    "Activate",            "V",0,    0,    (APTR) ID_ACTIVATE            },
  1223.     { NM_ITEM,    "Deactivate",        "D",0,    0,    (APTR) ID_DEACTIVATE        },
  1224.     { NM_ITEM,    "Toggle",            "T",0,    0,    (APTR) ID_TOGGLE            },
  1225.     { NM_ITEM,    "Restore",            "R",0,    0,    (APTR) ID_RESTORE            },
  1226.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1227.     { NM_ITEM,    "Edit Tooltypes",    "O",0,    0,    (APTR) ID_EDIT                },
  1228.  
  1229.  
  1230.     { NM_END,    NULL,                0,    0,    0,    0                            },
  1231. };
  1232.  
  1233.  
  1234.  
  1235.  
  1236. /*** main ***/
  1237.  
  1238. int main(int argc, char *argv[])
  1239. {
  1240.     /*** init ***/
  1241.     BOOL not_end = TRUE;
  1242.  
  1243.     init();
  1244.  
  1245.  
  1246.     /*** create mui-application ***/
  1247.     app = ApplicationObject,
  1248.         MUIA_Application_Title,                "WbMan",
  1249.         MUIA_Application_Version,            "$VER: WbMan 0.42 (27.8.93)",
  1250.         MUIA_Application_Copyright,            "© 1993 by kMel, Klaus Melchior",
  1251.         MUIA_Application_Author,            "Klaus Melchior",
  1252.         MUIA_Application_Description,        "Manages the WBStartup",
  1253.         MUIA_Application_Base,                "WBMAN",
  1254.         MUIA_Application_Menu,                menu_list,
  1255.         MUIA_Application_Commands,            arexx_list,
  1256.         MUIA_Application_SingleTask,        TRUE,
  1257.         MUIA_Application_DiskObject,        &wbman_sleep_dobj,
  1258.  
  1259.         SubWindow, wi_main = WindowObject,
  1260.             MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  1261.             MUIA_Window_Title, "WbMan",
  1262.             WindowContents, VGroup,
  1263.                 Child, VGroup,
  1264.                     Child, tx_info = TextObject,
  1265.                         TextFrame,
  1266.                         MUIA_Background, MUII_TextBack,
  1267.                         End,
  1268.                     Child, VGroup,
  1269.                         GroupSpacing(0),
  1270.                         Child, lv_tools = ListviewObject,
  1271.                             MUIA_Listview_MultiSelect, TRUE,
  1272.                             MUIA_Listview_DoubleClick, TRUE,
  1273.                             MUIA_Listview_List, ListObject,
  1274.                                 InputListFrame,
  1275.                                 MUIA_List_ConstructHook, &tools_list_conhook,
  1276.                                 MUIA_List_DestructHook, &tools_list_deshook,
  1277.                                 MUIA_List_CompareHook, &tools_list_cmphook,
  1278.                                 MUIA_List_DisplayHook, &tools_list_dsphook,
  1279.                                 End,
  1280.                             End,
  1281.                         Child, HGroup,
  1282.                             GroupSpacing(0),
  1283.                             Child, bt_activate        = SimpleButton("_Activate"),
  1284.                             Child, bt_toggle        = SimpleButton("_Toggle"),
  1285.                             Child, bt_deactivate    = SimpleButton("_Deactivate"),
  1286.                             End,
  1287.                         Child, HGroup,
  1288.                             GroupSpacing(0),
  1289.                             Child, bt_edit            = SimpleButton("_Edit Tooltypes"),
  1290.                             End,
  1291.                         End,
  1292.                     End,
  1293.                 Child, VSpace(2),
  1294.                 Child, HGroup,
  1295.                     MUIA_Group_SameSize, TRUE,
  1296.                     Child, bt_perform = SimpleButton("_Perform"),
  1297.                     Child, HSpace(0),
  1298.                     Child, bt_quit = SimpleButton("_Quit"),
  1299.                     End,
  1300.                 End,
  1301.             End,
  1302.         End;
  1303.  
  1304.  
  1305.     /*** application failed ? ***/
  1306.     if (!app)
  1307.         fail(app, "Creating application failed !");
  1308.  
  1309.     /*** connections & cycle ***/
  1310.     DoMethod(wi_main,        MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  1311.  
  1312.     DoMethod(bt_activate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_ACTIVATE        );
  1313.     DoMethod(bt_toggle,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_TOGGLE        );
  1314.     DoMethod(bt_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_DEACTIVATE    );
  1315.     DoMethod(bt_edit,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_EDIT            );
  1316.  
  1317.     DoMethod(bt_perform,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_PERFORM        );
  1318.     DoMethod(bt_quit,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  1319.  
  1320.     DoMethod(lv_tools,        MUIM_Notify,    MUIA_Listview_DoubleClick,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_EDIT            );
  1321.     DoMethod(lv_tools,        MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_LV_ACTIVE    );
  1322.  
  1323.     DoMethod(lv_tools, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  1324.         app, 2,
  1325.         MUIM_Application_ReturnID, ID_LV_ACTIVE);
  1326.  
  1327.     DoMethod(wi_main,        MUIM_Window_SetCycleChain,
  1328.         lv_tools,
  1329.         bt_activate, bt_toggle, bt_deactivate,
  1330.         bt_perform, bt_quit,
  1331.         NULL);
  1332.  
  1333.  
  1334.     /*** open window ***/
  1335.     set(wi_main, MUIA_Window_Open,            TRUE);
  1336.     set(wi_main, MUIA_Window_DefaultObject,    lv_tools);
  1337.  
  1338.  
  1339.     /*** get files ***/
  1340.     rescan_tools_list();
  1341.     count_tools_list();
  1342.  
  1343.     /*** set cursor on listview & check disable gadget ***/
  1344.     check_entries();
  1345.  
  1346.     /*** main-loop ***/
  1347.     while (not_end)
  1348.     {
  1349.         ULONG signal, id;
  1350.         ULONG pos;
  1351.         char *line;
  1352.  
  1353.         switch (id = DoMethod(app, MUIM_Application_Input, &signal))
  1354.         {
  1355.             case ID_ABOUT:
  1356.                 MUI_Request(app, wi_main, 0, NULL, "OK",
  1357.                     eC ePW "WbMan\n\n"
  1358.                     ePB "WbMan 0.41 (13.8.93)\n"
  1359.                     "Copyright 1993 by kMel, Klaus Melchior.\n"
  1360.                     "\nThis is a MUI-Application.\n"
  1361.                     "MUI is copyrighted by Stefan Stuntz.",
  1362.                     TAG_END);
  1363.             break;
  1364.  
  1365.             case MUIV_Application_ReturnID_Quit:
  1366.             case ID_QUIT:
  1367.                 not_end = FALSE;
  1368.             break;
  1369.  
  1370.             case ID_PERFORM:
  1371.                 rename_tools_list();
  1372.                 not_end = FALSE;
  1373.             break;
  1374.  
  1375.  
  1376.             case ID_EDIT:
  1377.                 if (!edit_window_open)
  1378.                 {
  1379.                     edit_window_open = TRUE;
  1380.  
  1381.                     /*** main-window must sleep now ***/
  1382.                     set(wi_main, MUIA_Window_Sleep, TRUE);
  1383.  
  1384.                     edit_tooltypes_entry();
  1385.                 }
  1386.             break;
  1387.  
  1388.             case ID_LV_ACTIVE:
  1389.                 check_entries();
  1390.             break;
  1391.  
  1392.  
  1393.             case ID_RESCAN:
  1394.                 rescan_tools_list();
  1395.                 check_entries();
  1396.                 count_tools_list();
  1397.             break;
  1398.  
  1399.             case ID_ACTIVATE:
  1400.                 change_tools_list(MODE_ACTIVATE);
  1401.                 check_entries();
  1402.                 count_tools_list();
  1403.             break;
  1404.  
  1405.             case ID_DEACTIVATE:
  1406.                 change_tools_list(MODE_DEACTIVATE);
  1407.                 check_entries();
  1408.                 count_tools_list();
  1409.             break;
  1410.  
  1411.             case ID_TOGGLE:
  1412.                 change_tools_list(MODE_TOGGLE);
  1413.                 check_entries();
  1414.                 count_tools_list();
  1415.             break;
  1416.  
  1417.             case ID_RESTORE:
  1418.                 change_tools_list(MODE_RESTORE);
  1419.                 check_entries();
  1420.                 count_tools_list();
  1421.             break;
  1422.  
  1423.  
  1424.             /*** pattern window ***/
  1425.  
  1426.             case ID_SELECT_ALL:
  1427.                 select_tools_list(MUIV_List_Select_On);
  1428.                 check_entries();
  1429.             break;
  1430.  
  1431.             case ID_SELECT_NONE:
  1432.                 select_tools_list(MUIV_List_Select_Off);
  1433.                 check_entries();
  1434.             break;
  1435.  
  1436.             case ID_SELECT_PATTERN:
  1437.                 if (!string_request_open)
  1438.                 {
  1439.                     string_request_open = TRUE;
  1440.  
  1441.                     /*** main-window must sleep now ***/
  1442.                     set(wi_main, MUIA_Window_Sleep, TRUE);
  1443.  
  1444.                     open_string_request("Pattern", 127);
  1445.                 }
  1446.             break;
  1447.  
  1448.  
  1449.             case ID_STRING_OK:
  1450.                 /*** get pattern ***/
  1451.                 get(st_string, MUIA_String_Contents, &line);
  1452.  
  1453.                 /*** clear list & select matching pattern ***/
  1454.                 select_tools_list(MUIV_List_Select_Off);
  1455.                 select_pattern_tools_list(line);
  1456.  
  1457.                 close_string_request();
  1458.                 string_request_open = FALSE;
  1459.                 check_entries();
  1460.             break;
  1461.  
  1462.             case ID_STRING_CANCEL:
  1463.                 close_string_request();
  1464.                 string_request_open = FALSE;
  1465.             break;
  1466.  
  1467.  
  1468.  
  1469.             /*** edit window ***/
  1470.  
  1471.             case ID_EDIT_LV_ACTIVE:
  1472.                 /*** copy active line into string ***/
  1473.                 DoMethod(lv_edit, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  1474.                 set(st_edit_string, MUIA_String_Contents, line);
  1475.                 check_edit_entries();
  1476.                 set(wi_edit, MUIA_Window_ActiveObject, st_edit_string);
  1477.             break;
  1478.  
  1479.  
  1480.             case ID_EDIT_NEW:
  1481.                 line = ">> new <<";
  1482.  
  1483.                 /*** insert at cursor-position ***/
  1484.                 get(lv_edit, MUIA_List_Active, &pos);
  1485.                 if (pos == -1)
  1486.                     pos = 0;
  1487.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1488.                 set(lv_edit, MUIA_List_Active, pos);
  1489.  
  1490.                 check_edit_entries();
  1491.             break;
  1492.  
  1493.             case ID_EDIT_COPY:
  1494.                 get(lv_edit, MUIA_List_Active, &pos);
  1495.                 DoMethod(lv_edit, MUIM_List_GetEntry, pos, &line);
  1496.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1497.                 set(lv_edit, MUIA_List_Active, pos);
  1498.             break;
  1499.  
  1500.             case ID_EDIT_REMOVE:
  1501.                 get(lv_edit, MUIA_List_Active, &pos);
  1502.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1503.  
  1504.                 check_edit_entries();
  1505.             break;
  1506.  
  1507.             case ID_EDIT_ACTIVATE:
  1508.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1509.                 get(lv_edit, MUIA_List_Active, &pos);
  1510.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1511.                 get(st_edit_string, MUIA_String_Contents, &line);
  1512.  
  1513.                 {
  1514.                     char *new_line, *insert_line;
  1515.  
  1516.                     new_line = strdup(line);
  1517.                     if (new_line)
  1518.                     {
  1519.                         *(new_line + strlen(new_line) - 1) = 0;
  1520.                         insert_line = new_line + 1;
  1521.                         DoMethod(lv_edit, MUIM_List_Insert, &insert_line, 1, pos);
  1522.                         free(new_line);
  1523.                     }
  1524.  
  1525.                 }
  1526.  
  1527.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1528.                 set(lv_edit, MUIA_List_Active, pos);
  1529.                 check_edit_entries();
  1530.             break;
  1531.  
  1532.             case ID_EDIT_DEACTIVATE:
  1533.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1534.                 get(lv_edit, MUIA_List_Active, &pos);
  1535.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1536.                 get(st_edit_string, MUIA_String_Contents, &line);
  1537.  
  1538.                 {
  1539.                     char *insert_line;
  1540.  
  1541.                     if (insert_line = AllocMem(MAXNAMELEN, MEMF_ANY))
  1542.                     {
  1543.                         sprintf(insert_line, "(%s)", line);
  1544.                         DoMethod(lv_edit, MUIM_List_Insert, &insert_line, 1, pos);
  1545.  
  1546.                         FreeMem(insert_line, MAXNAMELEN);
  1547.                     }
  1548.                 }
  1549.  
  1550.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1551.                 set(lv_edit, MUIA_List_Active, pos);
  1552.                 check_edit_entries();
  1553.             break;
  1554.  
  1555.  
  1556.             case ID_EDIT_ST_READY:
  1557.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1558.                 get(lv_edit, MUIA_List_Active, &pos);
  1559.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1560.                 get(st_edit_string, MUIA_String_Contents, &line);
  1561.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1562.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1563.                 set(lv_edit, MUIA_List_Active, pos);
  1564.             break;
  1565.  
  1566.  
  1567.             case ID_EDIT_SAVE:
  1568.                 save_tooltypes();
  1569.                 close_edit_window();
  1570.                 edit_window_open = FALSE;
  1571.             break;
  1572.  
  1573.             case ID_EDIT_CANCEL:
  1574.                 close_edit_window();
  1575.                 edit_window_open = FALSE;
  1576.             break;
  1577.  
  1578.  
  1579.             /*** default ***/
  1580.  
  1581.             default:
  1582.                 if (id)
  1583.                     printf("ID: %d = %08lx\n", id, id);
  1584.             break;
  1585.         }
  1586.  
  1587.         if (not_end && signal)
  1588.             Wait(signal);
  1589.     }
  1590.  
  1591.     fail(app, NULL);
  1592. }
  1593.  
  1594.  
  1595.